﻿<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="/static/lib/html5shiv.js"></script>
<script type="text/javascript" src="/static/lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="/static/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="/static/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="/static/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="/static/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="/static/static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="/static/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>题目管理--蓝鸥题库管理系统</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 题目管理 <span class="c-gray en">&gt;</span> 题目列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="cl pd-5 bg-1 bk-gray">
        <a href="?" class="btn btn-primary radius">全部</a>
        <a href="?state=1" class="btn btn-success radius">已解决</a>
        <a href="?state=0" class="btn btn-warning radius">未解决</a>
        {% if userInfo.type == '管理员'%}
        <a class="btn btn-primary radius" href="javascript:;" onclick="questions_add('添加题目','/loadmin/questionAdd/','800')"><i class="Hui-iconfont">&#xe600;</i> 添加题目</a>
        <a class="btn btn-secondary radius" href="javascript:;" onclick="questionSetTeacher('题目批量--分配讲师',0)"><i class="Hui-iconfont">&#xe61d;</i> 批量分配</a>
        <a class="btn btn-secondary radius" href="javascript:;" onclick="questions_import()"><i class="Hui-iconfont">&#xe645;</i> 批量导入</a>
        <a class="radius" data-toggle="tooltip" data-placement="right" title="表格列名：title(标题)、subject(学科-值：PHP,Python,H5,MySQL,Java,Vue,React,Angular等)、answer(答案)、company(公司名称)、address(地址)。目前仅支持: excel"><i class="Hui-iconfont">&#xe633;</i></a>
        {% endif %}
        <span class="r">共有数据：<strong>{{ subjects_count }}</strong> 条</span>
    </div>
	<table class="table table-border table-bordered table-hover table-bg">
		<thead>
			<tr class="text-c">
                <th width="40"></th>
                <th width="40">ID</th>
				<th width="300">题目名称</th>
				<th width="60">学科</th>
				<th width="100">提问时间</th>
                <th width="50">提问人</th>
                <th width="50">解决人</th>
                <th width="40">状态</th>
				<th width="70">操作</th>
			</tr>
		</thead>
		<tbody>
            {% for subject in subjects %}
			<tr class="text-c">
                <td><input type="checkbox" value="{{ subject.id }}" data-tid="{{ subject.teacher_id }}" name="subject_id"></td>
				<td>{{ subject.id }}</td>
				<td>{{ subject.title }}</td>
                <td>{{ subject.subject }}</td>
                <td>{{ subject.add_time|date:"Y-m-d H:i:s" }}</td>
                <td>{{ subject.student_name}}</td>
                <td>{{ subject.teacher.name}}</td>
                <td>{% if subject.state %} <span class="label label-success radius">已解决</span> {% else %} <span class="label label-default radius">未解决</span> {% endif %}</td>
				<td class="f-14">
                    {% if not subject.teacher %}<a title="编辑" href="javascript:;" onclick="questionSetTeacher('{{ subject.title }}--分配讲师',{{ subject.id }})" style="text-decoration:none"><i class="Hui-iconfont">&#xe61d;</i></a>{% endif %}
                    <a title="编辑" href="javascript:;" onclick="user_edit('修改题目','/loadmin/questionEdit/{{ subject.id }}/')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                    {% if userInfo.type == '管理员' %}<a title="删除" href="javascript:;" onclick="question_del(this,{{ subject.id }})" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>{% endif %}</td>
			</tr>
            {% endfor %}
		</tbody>
	</table>
    <div id="pages" style="margin-top: 20px"></div>
</div>
<div id="modal-demo" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content radius">
			<div class="modal-header">
				<h3 class="modal-title"></h3>
				<a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
			</div>
			<div class="modal-body">
				{% for teacher in teachers %}
                    <label class="">
                        <input name="teacherId" type="radio" value="{{ teacher.id }}">
                        {{ teacher.name }}</label>
                {% endfor %}
			</div>
			<div class="modal-footer">
				<button class="btn btn-primary" onclick="qst()">确定</button>
				<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
			</div>
		</div>
	</div>
</div>

<div id="modal-questions" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content radius">
			<div class="modal-header">
				<h3 class="modaltitles">批量导入题目</h3>
				<a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
			</div>
			<div class="modal-body">
                <input type="file" class="btn btn-default radius" name="file">
			</div>
			<div class="modal-footer">
				<button class="btn btn-primary" onclick="qimport()">确定</button>
				<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
			</div>
		</div>
	</div>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/static/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/static/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/static/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/static/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/static/lib/laypage/1.2/laypage.js"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript">
var subject_id = 0;
/*题目-添加*/
function questions_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*题目-编辑*/
function user_edit(title,url,w,h){
	layer_show(title,url,w,h);
}
/*题目-删除*/
function question_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
	    $.post('/loadmin/questionDel/',{id:id ,csrfmiddlewaretoken:'{{ csrf_token  }}'},function (data) {
            var icon = 5
            if(data.code == 200) icon = 6
            layer.msg(data.msg,{time:2000,icon: icon},function () {
                if(data.code == 200){
                    location.reload()
                }
            });
        })
	});
}

/*题目-分配讲师*/
function questionSetTeacher(msg,id){
    $('.modal-title').html(msg)
    subject_id = id
    $("#modal-demo").modal("show")
}
/*题目-分配讲师提交后台*/
function qst(){
    var teacher_id = $('input:radio:checked').val()
    if(!subject_id){
        subject_id = ''
        $('input[name="subject_id"]').each(function (k,e) {
            if($(e).is(':checked')){
               subject_id += $(e).val() + ','
            }
        })
    }
    $.post('/loadmin/questionSetTeacher/',{teacher_id:teacher_id , subject_id: subject_id,csrfmiddlewaretoken:'{{ csrf_token }}'},function (data) {
        var icon = 5
        if(data.code == 200) icon = 6
        layer.msg(data.msg,{time:2000,icon: icon},function () {
            if(data.code == 200){
                location.reload()
            }
        });
    })
}
/*题目-批量导入*/
function questions_import(){
    $("#modal-questions").modal("show")
}
/*题目-批量导入提交后台*/
function qimport(){
    var files = $("input[name='file']").prop('files');
    var data = new FormData();
    data.append('questionFile', files[0]);  //参数名：file
    data.append('csrfmiddlewaretoken', '{{ csrf_token  }}')
    $.ajax({
        url: '/loadmin/questionImport/',
        type: 'POST',
        data: data,
        cache: false, //禁止浏览器对该URL的缓存
        contentType: false,
        processData: false,
        success: function(data){
            var icon = 5
            if(data.code == 200) icon = 6
            layer.msg(data.msg,{time:2000,icon: icon},function () {
                if(data.code == 200){
                    location.reload()
                }
            });
        }
    });
}

$(function () {
    laypage({
    cont: 'pages', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：&lt;div id="page1">&lt;/div>
    pages: {{ all_pages|default:1 }}, //通过后台拿到的总页数
    curr: {{ page|default:1 }}, //初始化当前页
    jump: function(e,first){ //触发分页后的回调
        console.log(e.curr,this.curr)
        if(!first){
            window.location.href='/loadmin/questions/?page=' + e.curr
        }
    }
});
    $('input[name="subject_id"]').change(function () {
        if($(this).data('tid')) $(this).removeAttr('checked');
    })
})

</script>
</body>
</html>